home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Pascal
/
SWar
/
SWSound.p
< prev
next >
Wrap
Text File
|
1995-06-15
|
4KB
|
155 lines
unit SWSound;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices,
{$ENDC}
Sound, Globals;
procedure AInitSnd;
function ASndPlay (my_snd_Handle: Handle): OSErr;
procedure AStopSnd;
function SndIsPlaying: Boolean;
implementation
var
gSndChannel0, gSndChannel1, gSndChannel2: SndChannelPtr;
gSndPlaying0, gSndPlaying1, gSndPlaying2: Boolean;
myCommand: SndCommand;
chan: Integer;
(*=========================================================*)
{ const}
{TRUE= 1;}
{FALSE= 0;}
{NIL= 0;}
procedure AInitSnd;
var
myErr: OSErr;
begin
myErr := noErr;
if (not gSndIsInitted) then
begin
chan := 0; {?}
gSndChannel0 := SndChannelPtr(NewPtrClear(sizeof(SndChannel)));
if (gSndChannel0 <> nil) then
begin
gSndChannel0^.qLength := stdQLength;
myErr := SndNewChannel(gSndChannel0, sampledSynth, initMono + initChanLeft, nil);
end; (* if *)
gSndPlaying0 := FALSE;
gSndChannel1 := SndChannelPtr(NewPtrClear(sizeof(SndChannel)));
if (gSndChannel1 <> nil) then
begin
gSndChannel1^.qLength := stdQLength;
myErr := SndNewChannel(gSndChannel1, sampledSynth, initMono + initChanLeft, nil);
end; (* if *)
gSndPlaying1 := FALSE;
gSndChannel2 := SndChannelPtr(NewPtrClear(sizeof(SndChannel)));
if (gSndChannel2 <> nil) then
begin
gSndChannel2^.qLength := stdQLength;
myErr := SndNewChannel(gSndChannel2, sampledSynth, initMono + initChanLeft, nil);
end; (* if *)
gSndPlaying2 := FALSE;
gSndIsInitted := TRUE;
end; (* if *)
end; (* AInitSnd() *)
function ASndPlay (my_snd_Handle: Handle): OSErr;
var
err: OSErr;
begin
err := noErr;
if (not gSoundOn) then
exit(ASndPlay);
chan := chan + 1;
if ((chan > 2) or (chan < 0)) then
chan := 0;
case chan of
0:
begin
gSndPlaying0 := FALSE;
myCommand.cmd := quietCmd;
err := SndDoImmediate(gSndChannel0, myCommand);
if err = noErr then
begin
{$IFC UNDEFINED THINK_PASCAL}
err := SndPlay(gSndChannel0, SndListHandle(My_snd_Handle), TRUE);
{$ELSEC}
err := SndPlay(gSndChannel0, My_snd_Handle, TRUE);
{$ENDC}
if err = noErr then
begin
gSndPlaying0 := TRUE;
end;
end;
end;
1:
begin
gSndPlaying1 := FALSE;
myCommand.cmd := quietCmd;
err := SndDoImmediate(gSndChannel1, myCommand);
if err = noErr then
begin
{$IFC UNDEFINED THINK_PASCAL}
err := SndPlay(gSndChannel1, SndListHandle(My_snd_Handle), TRUE);
{$ELSEC}
err := SndPlay(gSndChannel1, My_snd_Handle, TRUE);
{$ENDC}
if err = noErr then
begin
gSndPlaying1 := TRUE;
end;
end;
end;
2:
begin
gSndPlaying2 := FALSE;
myCommand.cmd := quietCmd;
err := SndDoImmediate(gSndChannel2, myCommand);
if err = noErr then
begin
{$IFC UNDEFINED THINK_PASCAL}
err := SndPlay(gSndChannel2, SndListHandle(My_snd_Handle), TRUE);
{$ELSEC}
err := SndPlay(gSndChannel2, My_snd_Handle, TRUE);
{$ENDC}
if (err = noErr) then
begin
gSndPlaying2 := TRUE;
end;
end;
end;
end; (* case *)
ASndPlay := err;
end; {ASndPlay}
procedure AStopSnd;
var
myErr: OSErr;
begin
myErr := noErr;
if (gSndIsInitted) then
begin
myErr := SndDisposeChannel(gSndChannel0, TRUE);
gSndPlaying0 := FALSE;
myErr := SndDisposeChannel(gSndChannel1, TRUE);
gSndPlaying1 := FALSE;
myErr := SndDisposeChannel(gSndChannel2, TRUE);
gSndPlaying2 := FALSE;
gSndIsInitted := FALSE;
end; (* if *)
end; (* AStopSnd() *)
end.